<?php
class FinanceAction extends CommonAction {
	public function index(){
			
		$myid = D('User')->where(' id = ' . session(C('USER_AUTH_KEY')))->getField('member_id');
		
		if($_GET['time']==NULL){
		$time=date('Y-m-d');
		}else{
		$time=$_GET['time'];	
		}
		
		
		$list=M('Shop_turnover')->where(' shop_id = '.$myid.' and date like "'.$time.'"')->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function order_list(){
	
		$myid=D('User')->where(' id = '.session(C('USER_AUTH_KEY')))->getField('member_id');
		
		if(!isset($_GET['time'])){
		$time=date('Y-m-d');
		}else{
		$time=$_GET['time'];	
		}
		
		 $this->listmap=' shop_id = '.$myid.' and date like "'.$time.'"';
	
		 
		 $this->initView();
		 $this->pagesize=5;
		 
         $this->_list('t','left join  `think_shop_turnover_log` as l on  t.id = l.turnover_id ','');
		foreach($this->list as $k => $v){
		$list[$k]=M('Order')->where(' id = '.$v['order_id'])->find();	
		}
	
        $this->assign('list',$list);
		$this->display();
		
	}
	
	 public function _list($rename = '', $join = '', $field='') {
        $map = $this->listmap;
		
		$order = 'l.id';
        $pagesize = $this->pagesize;
		$this->dao=M('Shop_turnover');
        //计算总页数
        if ($join != '' || $rename != '') { //链接查询

            $count = $this->dao->alias($rename)->join($join)->where($map)->count();

            import('ORG.Util.Page');
            //实例化分页类
			
            $p = new Page($count, $pagesize);
            $this->list = $this->dao->alias($rename)->join($join)->where($map)->order($order)->Field($field)->limit($p->firstRow . ',
	' . $p->listRows)->select();
            $this->pages = $p->show();
        } else {
            $count = $this->dao->where($map)->count();
            import('ORG.Util.Page');
            //实例化分页类
            $p = new Page($count, $pagesize);
            $this->list = $this->dao->where($map)->order($order)->limit($p->firstRow . ',
	' . $p->listRows)->select();
            $this->pages = $p->show();
        }
    }
}